package com.ninth_group.vo;


import java.sql.ResultSet;
import java.sql.SQLException;


public class TFHDataVO {
    private String cid;
    private int hour;
    private int temp;
    private String windDirection; //  风向
    private int windScale; //  风力等级
    private int aqi; //  AQI: 空气质量指数

    public static int getIntAqi(String aqiStr) {
        return switch (aqiStr) {
            case "优" -> (int) (Math.random() * (30 - 10 + 1)) + 10; // 10~30 的随机整数（包含10和30）
            case "良" -> (int) (Math.random() * (50 - 31 + 1)) + 31; // 31~50 的随机整数
            case "中" -> (int) (Math.random() * (70 - 51 + 1)) + 51; // 51~70 的随机整数
            case "差" -> (int) (Math.random() * (100 - 71 + 1)) + 71; // 71~100 的随机整数
            default -> (int) (Math.random() * (100 - 71 + 1)) + 71;
        };
    }

    public static TFHDataVO mapRow(ResultSet rs) throws SQLException {
        TFHDataVO tf = new TFHDataVO();
        tf.setCid(rs.getString("city_id"));
        tf.setHour(rs.getInt("hour"));
        tf.setTemp(Integer.parseInt(rs.getString("temp")));
        tf.setWindDirection(rs.getString("wind_direction"));
        tf.setWindScale(rs.getInt("wind_scale"));
        String aqiStr = rs.getString("aqi"); // 数据表存储的是字符串，需要转换成int类型
        tf.setAqi(getIntAqi(aqiStr));
        return tf;
    }

    public TFHDataVO() {
    }

    public TFHDataVO(String cid, int hour, int temp,
                     String windDirection, int windScale, int aqi) {
        this.cid = cid;
        this.hour = hour;
        this.temp = temp;
        this.windDirection = windDirection;
        this.windScale = windScale;
        this.aqi = aqi;
    }

    @Override
    public String toString() {
        return "TFHDataVO{" +
                "cid='" + cid + '\'' +
                ", hour=" + hour +
                ", temp=" + temp +
                ", windDirection='" + windDirection + '\'' +
                ", windScale=" + windScale +
                ", aqi='" + aqi + '\'' +
                '}';
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

    public int getHour() {
        return hour;
    }

    public void setHour(int hour) {
        this.hour = hour;
    }

    public int getTemp() {
        return temp;
    }

    public void setTemp(int temp) {
        this.temp = temp;
    }

    public String getWindDirection() {
        return windDirection;
    }

    public void setWindDirection(String windDirection) {
        this.windDirection = windDirection;
    }

    public int getWindScale() {
        return windScale;
    }

    public void setWindScale(int windScale) {
        this.windScale = windScale;
    }

    public int getAqi() {
        return aqi;
    }

    public void setAqi(int aqi) {
        this.aqi = aqi;
    }
}
